/* $Id: Settings.java 39 2009-07-24 22:48:06Z h_m_r@gmx.de $ */
package util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Locale;
import java.util.Properties;

import javax.swing.JFrame;

public class Settings {

	private static final long serialVersionUID = -4677418842530418248L;

	private static final String SETTINGS_PATH = "settings.properties";

	public static final String LOCALE = "locale";
	public static final String WORKING_DIR = "workingDir";

	private static Properties properties = new Properties();

	public static Locale getLocale() {
		return new Locale(properties.getProperty(LOCALE, Locale.getDefault().getLanguage()));
	}
	public static void setLocale(Locale locale) {
		properties.setProperty(LOCALE, locale.getLanguage());
		store();
	}

	public static String getWorkingDir() {
		return properties.getProperty(WORKING_DIR, "");
	}
	public static void setWorkingDir(String workingDir) {
		properties.setProperty(WORKING_DIR, workingDir);
		store();
	}

	private static void load() {
		try {
			InputStream istream;
			istream = new FileInputStream(SETTINGS_PATH);
			try {
				properties.load(istream);
			} finally {
				istream.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static void store() {
		try {
			OutputStream ostream;
			ostream = new FileOutputStream(SETTINGS_PATH);
			try {
				properties.store(ostream, null);
			} finally {
				ostream.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// load properties from settings file
	static {
		load();
	}

}
